package com.mrd.gtimpframe.service.impl;

import com.mrd.gtimpframe.entity.RejectRecord;
import com.mrd.gtimpframe.repository.DeclarationMapper;
import com.mrd.gtimpframe.repository.RejectRecordMapper;
import com.mrd.gtimpframe.service.RejectRecordService;
import com.mrd.util.StringUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by dusy on 2017/7/31.
 */
@Service

public class RejectRecordServiceImpl implements RejectRecordService {
    @Autowired
    private RejectRecordMapper rejectRecordMapper;
    @Autowired
    private DeclarationMapper declarationMapper;

    @Override
    @Transactional
    public int deleteByPrimaryKey(String id) {
        return rejectRecordMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public int insert(RejectRecord record) {
        if (StringUtils.isEmpty(record.getId())) {
            record.setId(StringUtils.getUUID());
        }
        return rejectRecordMapper.insert(record);
    }

    @Override
    @Transactional
    public int insertSelective(RejectRecord record) {
        if (StringUtils.isEmpty(record.getId())) {
            record.setId(StringUtils.getUUID());
        }
        return rejectRecordMapper.insertSelective(record);
    }

    @Override
    public RejectRecord selectByPrimaryKey(String id) {
        return rejectRecordMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional
    public int updateByPrimaryKeySelective(RejectRecord record) {
        return rejectRecordMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    @Transactional
    public int updateByPrimaryKey(RejectRecord record) {
        return rejectRecordMapper.updateByPrimaryKey(record);
    }

    /**
     * 根据非null属性查询
     */
    @Override
    public List<RejectRecord> selectSelective(RejectRecord params) {
        return rejectRecordMapper.selectSelective(params);
    }

    /**
     * 根据报关单ids查询未处理的驳回申请
     */
    @Override
    public List<RejectRecord> selectByDidsInit(String[] declarationIds) {
        return rejectRecordMapper.selectByDidsInit(declarationIds);
    }

    /**
     * 自定义查询条件及字段查询
     *
     * @param propertyMap 需要获取的报关单属性,whereCase:查询条件
     */
    @Override
    public List<RejectRecord> selectByWhereCase(Map<String, String> propertyMap) {
        return declarationMapper.selectByWhereCase(propertyMap);
    }
}
